package hellfire.platform.input;

import hellfire.platform.screens.AbstractGameScreen;
import hellfire.system.graphics.GLVec2;
import android.view.MotionEvent;

public abstract class AbstractButton implements TouchListener
{
	private boolean down = false;
	private AbstractGameScreen screen;
	
	public AbstractButton(AbstractGameScreen screen)
	{
		this.screen = screen;
	}
	
	public void onTouchEvent(MotionEvent e, GLVec2 pos)
	{
		if(e.getAction() == MotionEvent.ACTION_DOWN)
		{
			screen.focusTouchListener(this);
			down = true;
		}
		else if(e.getAction() == MotionEvent.ACTION_UP)
		{
			if(down)
			{
				event();
				screen.focusTouchListener(null);
			}
			down = false;
		}
		else if(e.getAction() == MotionEvent.ACTION_MOVE)
		{
			if(down)
			{
				if(!testPosition(pos))
				{
					//leave area
					down = false;
					screen.focusTouchListener(null);
				}
			}
			
		}
	}
	
	public abstract void event();
	
}
